


#ifndef KEYBOARDS_H
#define KEYBOARDS_H

#include <OIS.h>
#include <Ogre.h>

#include "OgreInitializeSettings.h"
#include "PhysicHandler.h"
#include "FileOps.h"

class OgreApplication;

enum Keymode{HOLD,ONPRESS,ONRELEASE,RELEASE};

class KeyboardValues{
public:
OIS::KeyCode id;
std::string functionname;
Keymode mode;
bool pressed;
};

class MouseValues{
public:
	OIS::MouseButtonID id;
	std::string functionname;
	Keymode mode;
	bool pressed;
};

class KeyboardMouseHandler{

private:

	Ogre::RenderWindow* ogre_window;
	OgreInitializeSettings* ogre_init_settings;

	OIS::InputManager* lInputManager;
	OIS::Mouse* lMouse;
	OIS::Keyboard* lKeyboard;
	OIS::JoyStick* lJoystick;

	std::string lWindowHandle;

	unsigned long deltatime;
	
	bool isactive;
	bool functionfiring;

	//keyboard_specs

	std::vector<KeyboardValues*>* keyboard_allocation;

	bool isloaded;
	char interchar;
	char endchar;
	//mouse_specs
	
	std::vector<MouseValues*>* mouse_button_allocation;
	std::string mouse_axis_function;
	
	bool mouse_inverted_y;
	float mouse_delta_x;
	float mouse_delta_y;

	//joystick_specs

	float joystick_axis_x_state;
	float joystick_axis_y_state;
	float joystick_axis_z_state;
	float joystick_axis_z_rotation_state;
	int joysick_cooliehat_state;

	//controlabel
	OgreApplication* ogreapp;
	
	
	void initNull();
	void init();
	
	void handleKeyboard();
	void handleMouse();
	void handleJoystick();
	void Functions(std::string name);

	//keyallocs

	static OIS::KeyCode getKeyCodeFromString(std::string code);
	static OIS::MouseButtonID getMouseButtonIDFromString(std::string code);
	static Keymode getModeFromString(std::string mode);

	static std::string getStringFromKeyCode(OIS::KeyCode code); 
	static std::string getStringFromMouseCode(OIS::MouseButtonID code);
	static std::string getStringFromMode(Keymode mode);

	
	void deactivateControls();
	void activateControls();

	

	public:

		KeyboardMouseHandler(OgreApplication* ogre);
		~KeyboardMouseHandler();

	
	static std::string getWindowHandle(Ogre::RenderWindow* window);
	
	void handleInputs(unsigned long dtime);
	
	OIS::Mouse* getMouse();
	OIS::Keyboard* getKeyboard();
		
	//keyboard_allocs

	void addManual(std::string hardware,std::string id,std::string functionname,std::string mode);
	void save(const char* path);
	void loadFile(const char* path);
	void unload();
	bool isLoaded();
	
	std::string* getCurrentPressedButton();

	bool isActive();
	void setActive(bool active);

	bool isFunctionFiring();
	void setFunctionFiring(bool firing);


};

#endif